 //1.公用样式
 require('../../assets/css/index.js');
 //当前页面样式
 require('./cour.less');
    //2.公用js
let dom=require('../../utils/dom.js');
let https=require('../../utils/https.js');
let uti=require('../../utils/utils.js');
let local=require('../../utils/local.js');

import * as echarts from 'echarts';
dom.ready(function(){
  let course=dom.getById('#course');
  let curriculum=dom.getById('#curriculum');
    dom.ft('exercise');
    tops('cour');
    function tops(pitch) {
        dom.getById('header').innerHTML = `
            <div id="exer" class="option ${pitch == 'exer' ? 'pitch' : ''}">跑步</div>
            <div id="riding" class="option ${pitch == 'riding' ? 'pitch' : ''}">骑行</div>
            <div id="cour" class="option ${pitch == 'cour' ? 'pitch' : ''}">训练课程</div>
        `
        topat();
    }
    function topat(){
        let he=document.querySelector('header');
          he.addEventListener('click',function(e){
            if(e.target.id==='exer'){
              location.href='./exercise.html';
            }
            if(e.target.id==='riding'){
              location.href='./riding.html';
            }
            if(e.target.id==='cour'){
              location.href='./cour.html';
            }
          })
          }
    https.get('/api/train/courseList',function(res){
      let appcurr=''
        res.data.map(function(v,i){
          if(i==0){
                 let appc=`
                <div data-id="${v.courseId}" class="img">
                <img src="${https.BASE_URL+v.imgurl}" alt="">
                <div class="texts">
                <div class="txtTop">${v.name}</div>
                <div>${v.desc}</div>
                </div>
                </div>
                `
          course.innerHTML=appc;
          }else{
            appcurr+=`
            <div data-id="${v.courseId}" class="curriculumimg">
            <img src="${https.BASE_URL+v.imgurl}" alt="">
            <div class="curriculumtexts">
                <div class="curriculumtxtTop">${v.name}</div>
                <div>${v.desc}</div>
            </div>
            </div>
            `
            curriculum.innerHTML=appcurr;
          }
        })   
    })
    course.addEventListener('click',function(e){
      // console.log(e.target.parentNode);
      let id=e.target.parentNode.dataset.id;
      if(id){
        local.set('id',id);
        location.href='./courseDetails.html'
        }
    });
    curriculum.addEventListener('click',function(e){
      let id=e.target.parentNode.dataset.id;
      if(id){
      local.set('id',id);
      location.href='./courseDetails.html'
      }
    });
 
      

})